package com.xinke.module.system.mapper.user;

import java.util.*;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xinke.component.common.pojo.PageResult;
import com.xinke.component.mybatis.mybatis.core.query.LambdaQueryWrapperExt;
import com.xinke.component.mybatis.mybatis.core.mapper.BaseMapperExt;
import com.xinke.module.system.model.entity.user.UserRoleDO;
import org.apache.ibatis.annotations.Mapper;
import com.xinke.module.system.model.vo.user.*;

/**
 * 用户和角色关联 Mapper
 *
 * @author yzx
 */
@Mapper
public interface UserRoleMapper extends BaseMapperExt<UserRoleDO> {

    default PageResult<UserRoleDO> selectPage(UserRolePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperExt<UserRoleDO>()
                .eqIfPresent(UserRoleDO::getUserId, reqVO.getUserId())
                .eqIfPresent(UserRoleDO::getRoleId, reqVO.getRoleId())
                .orderByDesc(UserRoleDO::getUserRoleId));
    }

    default List<UserRoleDO> selectListByUserId(Long userId) {
        return selectList(UserRoleDO::getUserId, userId);
    }

    default List<UserRoleDO> selectListByRoleIds(Collection<Long> roleIds) {
        return selectList(UserRoleDO::getRoleId, roleIds);
    }

    default void deleteListByUserId(Long userId) {
        delete(new LambdaQueryWrapper<UserRoleDO>().eq(UserRoleDO::getUserId, userId));
    }
}